from pms.common.views import PostFormula
from department.utils import assert_department_permissions, update_department, department_view
from department.models import Department


class API(PostFormula):

    def handle(self, req):
        did = req['id']
        mod = req['mod']
        assert_department_permissions(self.user.id, did, [2])
        return self.success_respond(
            department_view(
                update_department(
                    department=Department.objects.get(id=did),
                    view=mod
                )
            )
        )
